package com.otaviolube.bibliotecas;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

public class ServerFunctions {
	
	private JSONParser jsonParser;
	
	//Endereco do servidor
	private static String url = "a colocar ainda";
	
	//Construtor da classe Server Functions
	public ServerFunctions(){
		jsonParser = new JSONParser();
	}
	
	/*
	 * Funcao para a solicitacao de login
	 * @param email
	 * @param password
	 */
	
	public JSONObject loginUser(String email, String password){
		
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		//Passando os parametros para o metodo POST
		params.add(new BasicNameValuePair("tag", "login"));
		params.add(new BasicNameValuePair("email", email));
		params.add(new BasicNameValuePair("password", password));
		
		JSONObject json = new JSONObject();
		json = jsonParser.getJSONFromUrl(url, params);
	
		return json;
	}
	
	/*
	 * Funcao para cadastrar usuario no sistema
	 * @param name
	 * @param email
	 * @param password
	 */
	
	public JSONObject registerUser(String name, String email, String password){
		
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		//Passando os parametros para o metodo POST
		params.add(new BasicNameValuePair("tag", "register"));
		params.add(new BasicNameValuePair("username", name));
		params.add(new BasicNameValuePair("email", email));
		params.add(new BasicNameValuePair("password", password));
		//Seto inicialmente o id_avatar = 1 e o id_container = 1
		params.add(new BasicNameValuePair("id_avatar", "1"));
		//params.add(new BasicNameValuePair("id_container", "1"));
		
		JSONObject json = new JSONObject();
		json = jsonParser.getJSONFromUrl(url, params);
		
		return json;
		
	}
	
}
